package echat.future.cn.echat.my.view;

import android.content.Intent;
import android.support.v7.widget.GridLayoutManager;

import java.util.ArrayList;
import java.util.List;

import echat.future.cn.echat.R;
import echat.future.cn.echat.databinding.ActivitySetTagBinding;
import echat.future.cn.echat.my.adapter.TagAdapter;
import echat.future.cn.echat.my.api.UserApi;
import echat.future.cn.echat.my.bean.LabelBean;
import echat.future.cn.echat.my.utils.HttpUtilsRequst;
import echat.future.cn.echat.my.utils.UserHelper;
import echat.future.cn.echat.my.weight.Navagation.AdapterNavagation;
import echat.future.cn.echat.my.weight.Navagation.IBaseNavagation;

public class SetTagActivity extends BaseActivity<ActivitySetTagBinding>{

    private TagAdapter mAdapter;
    private List<LabelBean>  mDatas = new ArrayList<>();


    @Override
    public int layoutId() {
        return R.layout.activity_set_tag;
    }

    @Override
    public IBaseNavagation navagation() {
        return new AdapterNavagation(this).setTitle("选择形象标签",16,R.color.white).setBack(R.drawable.btn_back).setNavagationBackgroudColor(R.color.color_161823);
    }

    @Override
    public void initView() {
        mAdapter = new TagAdapter(mDatas);
        bind.recyclerView.setLayoutManager(new GridLayoutManager(this,4));
        bind.recyclerView.setAdapter(mAdapter);
        loadMsg();
        bind.confirm.setOnClickListener(v -> {
            if(mAdapter.getSelecetTags().size() !=2){
                toast("必须选择两个标签哦");
                return;
            }
            Intent intent = new Intent();
            intent.putStringArrayListExtra("data", (ArrayList<String>) mAdapter.getSelecetTags());
            intent.putExtra("ids",mAdapter.getSelecetIds());

            setResult(RESULT_OK,intent);
            finish();
        });
    }


    private void loadMsg(){
        new HttpUtilsRequst<List<LabelBean>>(this,HttpUtilsRequst.retrofitClient.create(UserApi.class)
        .getAuthLabe(UserHelper.getToken()))
                .setmOnRequstSuccessListener((HttpUtilsRequst.OnRequstSuccessListener<List<LabelBean>>) o -> {
                        mDatas.addAll(o);
                        mAdapter.notifyDataSetChanged();
                }).start();
    }
}
